package com.seveneight.baijiesteward.ui.main.model;

import android.content.Context;
import android.util.Log;

import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.bean.AnyBean;
import com.seveneight.baijiesteward.bean.BaseEntity;
import com.seveneight.baijiesteward.http.BaseModel;
import com.seveneight.baijiesteward.http.BaseObserver;
import com.seveneight.baijiesteward.http.MyCallBack;
import com.seveneight.baijiesteward.http.RetrofitFactory;
import com.seveneight.baijiesteward.ui.main.contract.ForgetPwdContract;

import okhttp3.RequestBody;

/**
 * Created by user1 on 2018/2/24.
 */

public class ForgetPwdModel extends BaseModel implements ForgetPwdContract.ForgetPwdModel {

    @Override
    public void getCode(Context context,RequestBody body, final MyCallBack<AnyBean> callBack) {
        RetrofitFactory.getInstence().API()
                .getCode(body)
                .compose(this.<BaseEntity<AnyBean>>setThread())
                .subscribe(new BaseObserver<AnyBean>(context,"正在发送验证码...") {

                    @Override
                    protected void onSuccees(BaseEntity<AnyBean> t) throws Exception {
                        Log.d("AuthCode", t.toString());
                        callBack.onSuccess(t.getData());
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {

                    }
                });
    }

    @Override
    public void changeLoginPwd(Context context,RequestBody body, final MyCallBack<AnyBean> callBack) {
        RetrofitFactory.getInstence().API()
                .changeLoginPwd(body)
                .compose(this.<BaseEntity<AnyBean>>setThread())
                .subscribe(new BaseObserver<AnyBean>(context) {
                    @Override
                    protected void onSuccees(BaseEntity<AnyBean> t) throws Exception {
                        callBack.onSuccess(t.getData());
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {

                    }
                });
    }

    @Override
    public void changeTradePwd(Context context,RequestBody body, final MyCallBack<AnyBean> callBack) {
        RetrofitFactory.getInstence().API()
                .changeDealPwd(body)
                .compose(this.<BaseEntity<AnyBean>>setThread())
                .subscribe(new BaseObserver<AnyBean>(context) {
                    @Override
                    protected void onSuccees(BaseEntity<AnyBean> t) throws Exception {
                        callBack.onSuccess(t.getData());
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {

                    }
                });
    }

}
